Add undocumented (grrr) trkseg tags to gpx track handling.
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 29 Oct 2002 03:07:40 +0000 (03:07 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 29 Oct 2002 03:07:40 +0000 (03:07 +0000)
Misc cleanups for tracks and routes.

gpsbabel/defs.h
gpsbabel/gpx.c
gpsbabel/mapsend.c
gpsbabel/route.c

index 4405c384df308ca98f4c10810616c0eb17d52708..1710e10e6bc9026d96b5c0a2c67d65b023396785 100644 (file)
@@ -152,9 +152,12 @@ typedef void (*ff_write) (void);
 void fprintdms(FILE *, const coord *, int);
 
 typedef void (*waypt_cb) (const waypoint *);
+typedef void (*route_hdr)(const route_head *);
+typedef void (*route_trl)(const route_head *);
 void waypt_add (waypoint *);
 void waypt_del (waypoint *);
 void waypt_disp_all(waypt_cb);
+void route(route_hdr, route_trl, waypt_cb);
 unsigned int waypt_count(void);
 
 route_head *route_head_alloc(void);
index 87338f63c0b98a27c044774a9769a4cad03a2cfa..dacf8cebb178df0b65be16fe38341dda848897bf 100644 (file)
@@ -257,6 +257,7 @@ gpx_wr_deinit(void)
 {
        fclose(ofd);
 }
+
 void
 gpx_read(void)
 {
@@ -275,6 +276,26 @@ gpx_read(void)
        }
 }
 
+/*
+ *
+ */
+static
+void
+gpx_write_time(const time_t timep)
+{
+       struct tm *tm = gmtime(&timep);
+       
+       fprintf(ofd, "<time>%02d-%02d-%02dT%02d:%02d:%02dZ</time>\n",
+               tm->tm_year+1900, 
+               tm->tm_mon+1, 
+               tm->tm_mday, 
+               tm->tm_hour, 
+               tm->tm_min, 
+               tm->tm_sec
+       );
+
+}
+
 static void
 gpx_waypt_pr(const waypoint *waypointp)
 {
@@ -292,6 +313,9 @@ gpx_waypt_pr(const waypoint *waypointp)
                fprintf(ofd, "<ele>\n%f\n</ele>\n",
                         waypointp->position.altitude.altitude_meters);
        }
+       if (waypointp->creation_time) {
+               gpx_write_time(waypointp->creation_time);
+       }
        if (waypointp->url) {
                fprintf(ofd, "<url>%s</url>\n", waypointp->url);
        }
@@ -302,6 +326,43 @@ gpx_waypt_pr(const waypoint *waypointp)
        fprintf(ofd, "</wpt>\n");
 }
 
+static void
+gpx_track_hdr(route_head *rte)
+{
+       fprintf(ofd, "<trk>\n");
+       if (rte->rte_name) {
+               fprintf(ofd, "  <name>\n");
+               fprintf(ofd, "  <![CDATA[%s]]>\n",rte->rte_name);
+               fprintf(ofd, "  </name>\n");
+       }
+       fprintf(ofd, "<trkseg>\n");
+}
+
+static void
+gpx_track_disp(const waypoint *waypointp)
+{
+       fprintf(ofd, "<trkpt lat=\"%lf\" lon=\"%lf\">\n",
+               waypointp->position.latitude.degrees,
+               waypointp->position.longitude.degrees);
+       if (waypointp->creation_time) {
+               gpx_write_time(waypointp->creation_time);
+       }
+       fprintf(ofd, "</trkpt>\n");
+}
+
+static void
+gpx_track_tlr(route_hdr *rte)
+{
+       fprintf(ofd, "</trkseg>\n");
+       fprintf(ofd, "</trk>\n");
+}
+
+static
+void gpx_track_pr()
+{
+       route_disp_all(gpx_track_hdr, gpx_track_tlr, gpx_track_disp);
+}
+
 void
 gpx_write(void)
 {
@@ -314,7 +375,11 @@ gpx_write(void)
        fprintf(ofd, "xmlns=\"http://www.topografix.com/GPX/1/0\"\n");
        fprintf(ofd, "xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd\">\n");
 
-       waypt_disp_all(gpx_waypt_pr);
+       switch(global_opts.objective) {
+               case trkdata: gpx_track_pr();
+               default:
+               case wptdata: waypt_disp_all(gpx_waypt_pr);
+       }
 
        fprintf(ofd, "</gpx>\n");
 }
index 44126a36ff9a8997042ec43f31dc1f003436818a..01df1b072ca8a267f059755a861dcc5a12d5bbe1 100644 (file)
@@ -294,9 +294,9 @@ mapsend_read(void)
                        mapsend_track_read();
                        break;
                case ms_type_log:
-                       fatal(MYNAME ", GPS logs not supported.\n", type);
+                       fatal(MYNAME ", GPS logs not supported.\n");
                case ms_type_rgn:
-                       fatal(MYNAME ", GPS regions not supported.\n", type);
+                       fatal(MYNAME ", GPS regions not supported.\n");
                default:
                        fatal(MYNAME ", unknown file type %d\n", type);
        }
@@ -343,7 +343,7 @@ n = 1;
 void
 mapsend_wpt_write(void)
 {
-       mapsend_hdr hdr = {13, "4D533330 MS", "30", ms_type_wpt};
+       mapsend_hdr hdr = {13, "4D533330 MS", "30", ms_type_wpt, 0};
        int wpt_count = waypt_count();
        int n = 0;
 
@@ -353,14 +353,16 @@ mapsend_wpt_write(void)
        waypt_disp_all(mapsend_waypt_pr);
 
        my_fwrite4(&n, mapsend_file_out);
-/* TODO: Impelment routes here */
+/* TODO: Implement routes here */
 }
 
+#if LATER
 void 
 mapsend_trk_write(void)
 {
-       mapsend_hdr hdr = {13, "4D533334 MS", "34", ms_type_track};
+       mapsend_hdr hdr = {13, "4D533334 MS", "34", ms_type_track, 0};
 }
+#endif
 
 ff_vecs_t mapsend_vecs = {
        mapsend_rd_init,
index 92c8f4a18f875b3fbe34472e7b32726281daa9a5..6a4edbcb1824e62e8f348ab9364cb05a78fe083c 100644 (file)
@@ -53,24 +53,26 @@ route_add_wpt(route_head *rte, waypoint *wpt)
 }
 
 void
-route_disp (route_head *rh)
+route_disp (const route_head *rh, waypt_cb cb )
 {
        queue *elem, *tmp;
-       printf("NEW ROUTE\n");
+//     printf("NEW ROUTE\n");
        QUEUE_FOR_EACH(&rh->waypoint_list, elem, tmp) {
                waypoint *waypointp;
                waypointp = (waypoint *) elem;
-                       waypt_disp(waypointp);
+                       (*cb)(waypointp);
        }
                
 }      
 void 
-route_disp_all()
+route_disp_all(route_hdr rh, route_trl rt, waypt_cb wc)
 {
        queue *elem, *tmp;
        QUEUE_FOR_EACH(&my_route_head, elem, tmp) {
-               route_head *rh;
-               rh = (route_head *) elem;
-               route_disp(rh);
+               const route_head *rhp;
+               rhp = (route_head *) elem;
+               (*rh)(rhp);
+               route_disp(rhp, wc);
+               (*rt)(rhp);
        }
 }